<template>
	<view>
		<view style="display:flex;justify-content:space-between;line-height: 100rpx;">
			<view @click="addsipdetail" style="width:750rpx;height: 100rpx;text-align:center;font-size: 36rpx;font-weight: bold;background-color: #00aaff;color: #fff;border-radius: 10rpx;">新增明细单</view>
		</view>
		<view v-for="(item, index) in cpatrolDetailList" :key="index">
			<view style="background-color: #fff;padding: 30rpx;border-radius: 30rpx;" @click="updateDetail(item.ipdid)">
				<view class="box">
					<view class="left" style="width: 400rpx;">{{item.inserttime}}</view> 
					<!-- <view :class="[item.status!='正常' ? 'right-red' : 'right-green']">{{item.status}}</view> -->
				</view>
				<view style="text-align: center;margin-top: 25rpx;font-size: 45rpx;font-weight: bold;">
					{{item.cproject}}</view>
				<view class="box">
					<view class="left">单号:</view>
					<view class="right">{{item.ipdid}}</view>
				</view>
				<view class="box" v-if="ptype=='03'">
					<view class="left">质量检查项目:</view>
					<view class="right">{{item.qtype}}</view>
				</view>
				<view class="box">
					<view class="left">巡查项目大类:</view>
					<view class="right">{{item.piid1}}</view>
				</view>
				<view class="box">
					<view class="left">巡查项目中类:</view>
					<view class="right">{{item.piid2}}</view>
				</view>
				<view class="box">
					<view class="left">巡查项目小类:</view>
					<view class="right">{{item.piid3}}</view>
				</view>
				<view class="box">
					<view class="left">隐患数量:</view>
					<view class="right">{{item.dangecount}}</view>
				</view>
				 <view class="box" v-if="ptype=='02'">
					<view class="left">隐患类别:</view>
					<view class="right">{{item.dangetype}}</view>
				</view>
				<view class="box" v-if="ptype=='02'">
					<view class="left">隐患范围:</view>
					<view class="right">{{item.dangerange}}</view>
				</view>
				<view class="box">
					<view class="left">得分:</view>
					<view class="right">{{item.ipdscore==null?'':item.ipdscore}}</view>
				</view>
				<view style="height: 1px;background-color: #00aaff; margin: 10px 0;"></view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		request
	} from '@/request/index.js';
	export default {
		data() {
			return {
				cpatrolList: [],
				cpatrolDetailList: [],
				showFilter:true,
				pmode: '',
				pModes: [],
				index: 0,
				presult: '',
				presults: [],
				presultindex: 0,
				cproject:'',
				cprojects:[],
				cprojectIndex:0,
				pid:'',
				userInfo:{},
				ptype:''
			}
		},
		onLoad(option) {
			var userInfo = uni.getStorageSync('user');
			if (userInfo == null || userInfo == 'null' || userInfo == '') {
				uni.showToast({
					title: "请先登录",
					success() {
						uni.reLaunch({
							url: "/pages/login/login"
						})
					}
				})
			
			}
			
			var _self = this;
			_self.userInfo = userInfo
		
			this.pid = option.pid
			this.ptype = option.ptype
			this.getSipdetail(this.pid)
			// this.getCpatrol()
			// this.getPmode()
			// this.getPresults()
			// this.getProjects()
		},
		onPullDownRefresh(){
			this.getSipdetail(this.pid)
		},
		methods: {
			
			
			getSipdetail(pid){
				var that = this
				var data = {}
				data = {query_pid:this.pid}
				data.sort = 'updatetime'
				data.order = 'desc'
				var uri=""
				if(this.ptype=='01'){
					uri = "/grid/query/c_cipdetail"
				}if(this.ptype=='02'){
					uri = "/grid/query/c_sipdetail"
				}if(this.ptype=='03'){
					uri = "/grid/query/c_qipdetail"
				}
				request({
					url: uri,
					method: "POST",
					data:data,
					header: {
						'Content-Type': 'application/x-www-form-urlencoded',
						'cookie': uni.getStorageSync('cookie')
					}
				}).then(res => {
					that.cpatrolDetailList = res.data.rows
				})
			},
			updateDetail(pid){
				uni.navigateTo({
					url:"/pages/updateSipDetail/updateSipDetail?ipdid="+pid+"&ptype="+this.ptype
				})
			},
			
			addsipdetail(){
				var pid = this.pid
				uni.redirectTo({
					url:"/pages/sipdetail/sipdetail?pid="+pid+"&ptype="+this.ptype
				})
			},
			filter(){
				var data = {}
				if(this.pmode.toString().trim()!=''){
					data.query_pmode = this.pmode
				}
				if(this.presult.toString().trim()!=''){
					data.query_presult = this.presult
				}
				
				if(this.cproject.toString().trim()!=''){
					data.query_cproject = this.cproject
				}
				this.getCpatrol(data)
			},
			
			getCpatrol(data) {
				var that = this
				request({
					url: "/thirdGrid/query/c_cpatrol-m_cpatrol",
					method: "POST",
					data: data,
					header: {
						'Content-Type': 'application/x-www-form-urlencoded',
						'cookie': uni.getStorageSync('cookie')
					}
				}).then(res => {
					
					if (res.data.success == true) {
						that.cpatrolList = res.data.rows
					} else {
						uni.showToast({
							title: res.data.msg,
							
						})
					}
				})
			},
			
			
			
			
			
			
			
			bindPickerChanges(e) {
				
				this.index = e.target.value
				this.pmode = this.pModes[this.index].id
			},
			bindPresultChanges(e) {
				
				this.presultindex = e.target.value
				this.presult = this.presults[this.presultindex].id
			},
			bindProtectChanges(e) {
				
				this.cprojectIndex = e.target.value
				this.cproject = this.cprojects[this.cprojectIndex].id
			},
			chargeFilter(){
				if(this.showFilter){
					this.showFilter = false
				}else{
					this.showFilter = true
				}
			},
			getPmode() {
				var that = this
				request({
					url: "/thirdWidget/comboJson/c_cpatrol-pmode",
					method: "POST",
					header: {
						'Content-Type': 'application/x-www-form-urlencoded',
						'cookie': uni.getStorageSync('cookie')
					}
				}).then(res => {
					
					if (res.data.code == '200') {
						that.pModes = []
						for (var i = 0; i < res.data.data.length; i++) {
							var mode = {}
							mode.id = res.data.data[i].id
							mode.cn = res.data.data[i].cn
							if (mode.id == '') {
								mode.id = ' '
								mode.cn = '无'
							}
							that.pModes.push(mode)
						}
						that.pmode = that.pModes[that.index].id
					} else {
						uni.showToast({
							title: res.data.msg,
							
						})
					}
				})
			},
			getPresults() {
				var that = this
				request({
					url: "/thirdWidget/comboJson/c_cpatrol-presult",
					method: "POST",
					header: {
						'Content-Type': 'application/x-www-form-urlencoded',
						'cookie': uni.getStorageSync('cookie')
					}
				}).then(res => {
					
					if (res.data.code == '200') {
						that.presults = []
						for (var i = 0; i < res.data.data.length; i++) {
			
							var result = {}
							result.id = res.data.data[i].id
							result.cn = res.data.data[i].cn
							if (result.id == '') {
								result.id = ' '
								result.cn = '无'
							}
							that.presults.push(result)
						}
						that.presult = that.presults[that.presultindex].id
			
					} else {
						uni.showToast({
							title: res.data.msg,
							
						})
					}
				})
			},
			getProjects() {
				var that = this
				request({
					url: "/thirdWidget/findJson?code=c_cpatrol&field=cproject",
					method: "POST",
					header: {
						'Content-Type': 'application/x-www-form-urlencoded',
						'cookie': uni.getStorageSync('cookie')
					}
				}).then(res => {
					
					if (res.data.success == true) {
						that.cprojects = [{id:' ',cn:'无'}]
						for (var i = 0; i < res.data.rows.length; i++) {
			
							var project = {}
							project.id = res.data.rows[i].cpid
							project.cn = res.data.rows[i].csname
							if (project.id == '') {
								project.id = ' '
								project.cn = '无'
							}
							that.cprojects.push(project)
						}
						that.cproject = that.cprojects[that.cprojectIndex].id
			
					} else {
						uni.showToast({
							title: res.data.msg,
							
						})
					}
				})
			},
		}
	}
</script>

<style>
	.box {
		display: flex;
		justify-content: space-between;
		margin-top: 25rpx;
	}

	.left {
		padding-left: 30rpx;
		color: #656565;
		width: 300rpx;
	}

	.right {
		padding-right: 30rpx;
		font-weight: bold;
		
	}
	.right-red {
		padding-right: 30rpx;
		font-weight: bold;
		background-color: red;border-radius: 10rpx;padding-left: 30rpx;color: #fff;
	}
	.right-green {
		padding-right: 30rpx;
		font-weight: bold;
		background-color: green;border-radius: 10rpx;padding-left: 30rpx;color: #fff;
	}
	.container {
		padding: 20px;
	}
	
	.input-row {
		margin-bottom: 20px;
		display: flex;
	
	}
	
	.input-row text {
		flex-grow: 1;
		margin-right: 10px;
	}
</style>